package Dao;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import Entity.Course;
import Entity.Maintenance;
import mapper.Coursemapper;
import mapper.Maintenancemapper;

public class maintenancedao implements Maintenancemapper{
	private static Maintenancemapper maintenancemapper;
	private static SqlSession session;

	public maintenancedao() throws IOException {
	 	String resource ="mybatis-config.xml";
		InputStream inputstream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlsessionfactory = new SqlSessionFactoryBuilder().build(inputstream);
		 session = sqlsessionfactory.openSession();
        maintenancemapper = session.getMapper(Maintenancemapper.class);
    }
	public void close(){
		this.session.close();
	}
	@Override
	public boolean CreatMaintenance(Maintenance maintenance) {
		
		Boolean iuser = this.maintenancemapper.CreatMaintenance(maintenance);
		if(iuser == true){
			session.commit();
		}else{
			session.rollback();
		}

		return iuser;
	}

	@Override
	public void deleteMaintenance(String rid, String mid) {
	
		this.maintenancemapper.deleteMaintenance(rid,mid);
		session.commit();

		
	}

	@Override
	public List<Maintenance> getAllMaintenance() {
	
		List<Maintenance> selectList = this.maintenancemapper.getAllMaintenance();

		return selectList;
	}

	@Override
	public List<Maintenance> getMaintenanceByrid(String rid) {
		
		List<Maintenance> selectList = this.maintenancemapper.getMaintenanceByrid(rid);

		return selectList;
	}
	

}
